

// const {mysql} = require('../qcloud')

// module.exports = async (ctx)=>{
//   const {bookid,comment,openid,location,phone} = ctx.request.body
//   console.log(bookid,comment,openid,location,phone)
//   try {
//     await mysql('comments').insert({bookid,comment,openid,location,phone})
//     ctx.state.data = {
//       msg: 'success'
//     }
//   } catch(e){
//     ctx.state = {
//       code: -1,
//       data:{
//         msg: '评论失败' + e.sqlMessage
//       }
//     }
//   }
// }




const {mysql} = require('../qcloud')

module.exports = async (ctx) => {
    const {openid, bookid, comment, phone, location,time} = ctx.request.body
    console.log(openid, bookid, comment, phone, location,time)
    try {
        await mysql('comments').insert({openid, bookid, comment, phone, location,time})
        ctx.state.data = {
            msg: 'success'
        }
    } catch (e) {
        ctx.state = {
            code: -1,
            data: {
                msg: '评论失败:' + e.sqlMessage
            }
        }
    }
}